package com.lhkj.ct.framework.shiro.token;

import com.alibaba.fastjson2.annotation.JSONField;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.RememberMeAuthenticationToken;

/**
 *  <p>
 *      账号密码登录
 *  </p>
 */
public class UsernamePasswordAuthToken implements AuthenticationToken, RememberMeAuthenticationToken {

    private static final long serialVersionUID = 1L;

    /**
     * 这里使用账号
     */
    private String username;

    /**
     * 用户类型
     */
    private Integer userType;

    /**
     * 是否免密，默认false
     * true为可免密登录
     * false为需密码登录
     */
    private boolean noPassword = false;


    /**
     * 加密过后的密码
     */
    private String password;

    /**
     * 验证码的key
     */
    private String verKey;

    /**
     * 验证码
     */
    private String kaptcha;

    /**
     * 是否使用记住我
     */
    private boolean rememberMe;

    public UsernamePasswordAuthToken(String username, String password, boolean rememberMe) {
        super();
        this.username = username;
        this.password = password;
        this.rememberMe = rememberMe;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }

    public boolean isNoPassword() {
        return noPassword;
    }

    public void setNoPassword(boolean noPassword) {
        this.noPassword = noPassword;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getVerKey() {
        return verKey;
    }

    public void setVerKey(String verKey) {
        this.verKey = verKey;
    }

    public String getKaptcha() {
        return kaptcha;
    }

    public void setKaptcha(String kaptcha) {
        this.kaptcha = kaptcha;
    }

    public void setRememberMe(boolean rememberMe) {
        this.rememberMe = rememberMe;
    }

    @Override
    public boolean isRememberMe() {
        return rememberMe;
    }

    @Override
    @JSONField(deserialize = false, serialize = false)
    public Object getCredentials() {
        return this.password.toCharArray();
    }

    @Override
    @JSONField(deserialize = false, serialize = false)
    public String getPrincipal() {
        return username;
    }

    @Override
    public String toString() {
        return "WebAuthenticationToken{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", rememberMe=" + rememberMe +
                '}';
    }
}
